package com.chpro.freemarker.util;

public class StringUtils {
	
	/**
	 * 将一个名称转为驼峰类型的名称 主要用于将 表名转换为类开 jmcs_cust_info 将转换成JmcsCustInfo
	 * @param name
	 * @return
	 */
	public static String toHump(String name){
		if(name==null||"".equals(name)){
			System.out.println("name为null或等于空");
			return "";
		}
		StringBuffer result = new StringBuffer();
		String[] names = name.split("_");
		for(String str:names){
			String first = str.substring(0, 1).toUpperCase();
			String rest = str.substring(1, str.length());
			result.append(new StringBuffer(first).append(rest).toString());
		}
		return result.toString();
	}
	
	/**
	 * 此方法主要是将一个表名字段 名 转换为 一个类的字段名 符合驼峰标识
	 * @param name
	 * @return
	 */
	public static String toColumn(String name){
		if(name==null||"".equals(name)){
			System.out.println("name为null或等于空");
			return "";
		}
		StringBuffer result = new StringBuffer();
		String[] names = name.split("_");
		int i=0;
		for(String str:names){
			String first = "";
			if(i==0)
				first = str.substring(0, 1);
			else
				first = str.substring(0, 1).toUpperCase();
			
			String rest = str.substring(1, str.length());
			result.append(new StringBuffer(first).append(rest).toString());
			i++;
		}
		return result.toString();
	}
}
